package com.uw.uwregistry.config;


import com.uw.uwregistry.cluster.Cluster;
import com.uw.uwregistry.health.HealthChecker;
import com.uw.uwregistry.health.UWHealthChecker;
import com.uw.uwregistry.service.RegistryService;
import com.uw.uwregistry.service.UWRegistryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@EnableConfigurationProperties(UwRegistryConfigProperties.class)
@SpringBootConfiguration
public class UwRegistryConfig {


    @Bean
    public RegistryService registryService() {
        return new UWRegistryService();
    }

    @Bean(initMethod = "start", destroyMethod = "stop")
    public HealthChecker healthChecker(@Autowired RegistryService registryService) {
        return new UWHealthChecker(registryService);
    }

    @Bean(initMethod = "start", destroyMethod = "stop")
    public Cluster cluster(@Autowired UwRegistryConfigProperties uwRegistryConfigProperties) {
        return new Cluster(uwRegistryConfigProperties);
    }

}
